<%@ include file="/WEB-INF/jsp/include/taglib.jsp" %>

<c:choose>
    <c:when test="${empty entries}">
        <fmt:message key="app.calendar.empty"/>
    </c:when>
    <c:otherwise>
        <a href="<c:url value="/addride.form"/>?date=<c:out value="${calendarDate}"/>">
            <fmt:message key="app.calendar.add"/>
        </a>
    </c:otherwise>
</c:choose>
<br/><br/>

<c:forEach items="${entries}" var="entry">
    <div class="entry">
        <div class="entry-left">
            <img src="/static-images/pic-helmet.gif">
        </div>
        <div class="entry-right">
            <div class="entry-header">
                <a href="<c:url value="/viewride.form/${entry.id}"/>">
                    <c:out value="${entry.header}"/>
                </a>
            </div>
            <div class="entry-data">
                <fmt:formatDate value="${entry.date}"/>
                <a href="<c:url value="/viewprofile.form/${entry.author.username}"/>">
                    <c:out value="${entry.author.fullname}"/>
                </a>
            </div>
            <div class="entry-text">
                <c:out value="${entry:preview(entry.text)}" escapeXml="false"/>
                <c:if test="${entry:isShortened(entry.text)}">
                    <a href="<c:url value="/viewride.form/${entry.id}"/>"><fmt:message key="app.entry.readEntire"/></a>
                </c:if>
            </div>
            <div class="entry-text">
                <c:if test="${!empty entry.pictures}">
                    <a href="<c:url value="/viewentry.form/${entry.id}"/>">
                        <fmt:message key="app.ride.photos"/>
                    </a>
                </c:if>
            </div>
            <div class="entry-comment-footer">
                <c:choose>
                    <c:when test="${entry:isAllowedEditing(entry, pageContext.request.remoteUser)}">
                        <a href="<c:url value="/editride.form/${entry.id}"/>">
                            <fmt:message key="app.ride.edit"/>
                        </a>
                        <c:if test="${not entry.cancelled}">
                            .. <a href="<c:url value="/cancelride.form/${entry.id}"/>"
                                  onclick="return confirm('<fmt:message key="app.ride.cancel.confirm"/>');">
                            <fmt:message key="app.ride.cancel"/>
                        </a>
                        </c:if>
                    </c:when>
                    <c:otherwise>
                        <c:choose>
                            <c:when test="${entry:isUserOnRide(entry, pageContext.request.remoteUser)}">
                                <a href="<c:url value="/splitride.form/${entry.id}"/>">
                                    <fmt:message key="app.ride.split"/>
                                </a>
                            </c:when>
                            <c:otherwise>
                                <c:if test="${not entry.cancelled}">
                                    <a href="<c:url value="/joinride.form/${entry.id}"/>">
                                        <fmt:message key="app.ride.join"/>
                                    </a>
                                </c:if>
                            </c:otherwise>
                        </c:choose>
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
    </div>
</c:forEach>

<a href="<c:url value="/addride.form"/>?date=<c:out value="${calendarDate}"/>">
    <fmt:message key="app.calendar.add"/>
</a>

